package club.banyuan.service;

import club.banyuan.bean.Blog;
import club.banyuan.dao.BlogDao;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BlogService {
    private BlogDao blogDao;

    @Autowired
    public BlogService(BlogDao blogDao) {
        this.blogDao = blogDao;
    }

    public PageInfo<Blog> getBlogs(Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo<Blog>(blogDao.getAllBlogs());
    }

    public PageInfo<Blog> getBlogsByUser(Integer pageNum, Integer pageSize,String username){
        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo<Blog>(blogDao.getBlogsByUser(username));
    }

    public Blog getBlogById(Integer blogId){
        return blogDao.getBlogByBlogId(blogId);
    }

    public Blog findBlogDetail(Integer blogId){
        return blogDao.getBlogByBlogId(blogId);
    }
}
